<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电力消费数据分析</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
    <style>
        /* 大屏样式调整 */
        body {
            font-size: 1.2rem;
        }
        .card {
            margin-bottom: 2rem;
        }
        .card-header {
            font-size: 1.5rem;
        }
        .table th, .table td {
            font-size: 1.2rem;
        }

        /* 响应式设计 */
        @media (min-width: 1200px) {
            .container {
                max-width: 90%;
            }
        }

        /* 新增热力图容器样式 */
        #heatmap-container {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        body{zoom:100%}

        #relationshipChartContainer {
            display:flex;
            justify-content: center;
            align-items: center;
        }
        #load-comparison-container{
            display:flex;
            justify-content: center;
            align-items: center;
        }
        #weather-load-pie-chart-container{
            display:flex;
            justify-content: center;
            align-items: center;
        }
        #loadCurveContainer{
            display:flex;
            justify-content: center;
            align-items: center;
        }
        .form-select {
        width: 150px; /* 可以根据需要调整宽度 */
        font-align:center;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
        <div class="container">
            <a class="navbar-brand fw-bold" href="#">
                <i class="bi bi-lightning-charge me-2"></i>光棱数据电力消费数据分析与预测
            </a>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item"></li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="#data-analysis" id="dataAnalysisTab">
                            <i class="bi bi-graph-up me-1"></i>数据分析
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#data-forecast" id="dataForecastTab">
                            <i class="bi bi-magic me-1"></i>数据预测
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#history" id="historyTab">
                            <i class="bi bi-clock-history me-1"></i>历史记录
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-5 pt-4">  <!-- 添加pt-4给导航栏留出空间 -->
        <h1 class="text-left mb-4">电力消费数据分析</h1>

        <div class="row">
            <div class="col-md-4 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h2>数据集基本统计</h2>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>属性</th>
                                        <th>最大值</th>
                                        <th>最小值</th>
                                        <th>均值</th>
                                        <th>标准差</th>
                                    </tr>
                                </thead>
                                <tbody id="stats-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-8 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h3>相关性热力图</h3>
                    </div>
                    <div class="card-body" id="heatmap-container">
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h3>节假日影响</h3>
                    </div>
                    <div class="card-body" id="load-comparison-container">
                    </div>
                </div>
            </div>

            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h3>相关性分析</h3>
                    </div>
                     <div class="card-body" id="weather-load-pie-chart-container">
                </div>
            </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h3>用电量与其他特征的关系</h3>
                    </div>
                    <div class="card-body">
                    <select id="featureSelect" class="form-select mb-3">
                        <option value="Max_Temperature">最高温度</option>
                        <option value="Min_Temperature">最低温度</option>
                        <option value="Avg_Temperature">平均温度</option>
                        <option value="Avg_Humidity">平均湿度</option>
                        <option value="Rainfall">降雨量</option>
                    </select>
                    <div id="relationshipChartContainer"></div>
                    </div>
                </div>
            </div>
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h3>时刻负荷趋势图</h3>
                    </div>
                    <div class="card-body" id="loadCurveContainer">
                </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const selectedFeature = 'Max_Temperature';
            fetch(`/get_relationship_data?feature=${selectedFeature}`)
               .then(response => response.json())
               .then(data => {
                    if (data.status === 'success') {
                        const chartContainer = document.getElementById('relationshipChartContainer');
                        chartContainer.innerHTML = data.chart_html;

                        // 手动触发 pyecharts 渲染
                        const scriptTags = chartContainer.getElementsByTagName('script');
                        for (let i = 0; i < scriptTags.length; i++) {
                            const script = document.createElement('script');
                            script.innerHTML = scriptTags[i].innerHTML;
                            document.body.appendChild(script);
                        }
                    } else {
                        console.error(data.message);
                    }
                })
               .catch(error => {
                    console.error('请求出错:', error);
                });
        });
        document.getElementById('featureSelect').addEventListener('change', function() {
        const selectedFeature = this.value;
        fetch(`/get_relationship_data?feature=${selectedFeature}`)
           .then(response => response.json())
           .then(data => {
                if (data.status === 'success') {
                    const chartContainer = document.getElementById('relationshipChartContainer');
                    chartContainer.innerHTML = data.chart_html;

                    // 手动触发 pyecharts 渲染
                    const scriptTags = chartContainer.getElementsByTagName('script');
                    for (let i = 0; i < scriptTags.length; i++) {
                        const script = document.createElement('script');
                        script.innerHTML = scriptTags[i].innerHTML;
                        document.body.appendChild(script);
                    }
                } else {
                    console.error(data.message);
                }
            })
           .catch(error => {
                console.error('请求出错:', error);
            });
    });
        document.getElementById('dataAnalysisTab').addEventListener('click', function() {
            window.location.href ="{{ url_for('data_analysis') }}";
            console.log('数据分析标签被点击');
        });

        document.getElementById('dataForecastTab').addEventListener('click', function() {
            window.location.href = "{{ url_for('data_yuce') }}";
            console.log('数据预测标签被点击');
        });

        document.getElementById('historyTab').addEventListener('click', function() {
             window.location.href = "{{ url_for('data_history') }}";
            console.log('历史记录标签被点击');
        });

        // 获取相关性数据
        fetch('/get_correlation_data')
           .then(response => response.json())
           .then(data => {
                if (data.status === 'success') {
                    // 填充基本统计表格
                    const stats = data.stats;
                    const statsTableBody = document.getElementById('stats-table-body');
                    for (const attribute in stats) {
                        const row = document.createElement('tr');
                        row.innerHTML = `
                            <td>${attribute}</td>
                            <td>${stats[attribute].max}</td>
                            <td>${stats[attribute].min}</td>
                            <td>${stats[attribute].mean}</td>
                            <td>${stats[attribute].std}</td>
                        `;
                        statsTableBody.appendChild(row);
                    }

                    // 插入热力图
                    const heatmapContainer = document.getElementById('heatmap-container');
                    heatmapContainer.innerHTML = data.heatmap;

                    // 手动触发 pyecharts 渲染
                    const scriptTags = heatmapContainer.getElementsByTagName('script');
                    for (let i = 0; i < scriptTags.length; i++) {
                        const script = document.createElement('script');
                        script.innerHTML = scriptTags[i].innerHTML;
                        document.body.appendChild(script);
                    }
                } else {
                    console.error(data.message);
                }
            })
           .catch(error => {
                console.error('请求出错:', error);
            });

        // 获取节假日负荷对比数据
        fetch('/get_load_comparison')
           .then(response => response.json())
           .then(data => {
                if (data.status === 'success') {
                    // 插入负荷对比图表
                    const loadContainer = document.getElementById('load-comparison-container');
                    loadContainer.innerHTML = data.chart_html;

                    // 手动触发 pyecharts 渲染
                    const scriptTags = loadContainer.getElementsByTagName('script');
                    for (let i = 0; i < scriptTags.length; i++) {
                        const script = document.createElement('script');
                        script.innerHTML = scriptTags[i].innerHTML;
                        document.body.appendChild(script);
                    }
                } else {
                    console.error(data.message);
                }
            })
           .catch(error => {
                console.error('请求出错:', error);
            });

        // 获取气象因素 对负荷影响的饼状图数据
        fetch('/get_weather_load_pie_chart')
           .then(response => response.json())
           .then(data => {
                if (data.status === 'success') {
                    // 插入饼状图
                    const pieChartContainer = document.getElementById('weather-load-pie-chart-container');
                    pieChartContainer.innerHTML = data.chart_html;

                    // 手动触发 pyecharts 渲染
                    const scriptTags = pieChartContainer.getElementsByTagName('script');
                    for (let i = 0; i < scriptTags.length; i++) {
                        const script = document.createElement('script');
                        script.innerHTML = scriptTags[i].innerHTML;
                        document.body.appendChild(script);
                    }
                } else {
                    console.error(data.message);
                }
            })
           .catch(error => {
                console.error('请求出错:', error);
            });

        fetch('/get_load_curve_data')
   .then(response => response.json())
   .then(data => {
        if (data.status === 'success') {
            const container = document.getElementById('loadCurveContainer');
            container.innerHTML = data.chart_html;

            // 手动触发 pyecharts 渲染
            const scriptTags = container.getElementsByTagName('script');
            for (let i = 0; i < scriptTags.length; i++) {
                const script = document.createElement('script');
                script.innerHTML = scriptTags[i].innerHTML;
                document.body.appendChild(script);
            }
        } else {
            console.error(data.message);
        }
    })
   .catch(error => {
        console.error('请求出错:', error);
    });
    </script>

</body>
<footer class="footer mt-auto py-3 bg-light">
    <div class="container text-center">
        <span class="text-muted">© 2025电力消费数据分析系统</span>
    </div>
</footer>
</html>